/**   
* @Title: DaiZhongYwServiceImpl.java 
* @Package com.zjdiepu.www.biz.zpp 
* 
* @author zhangpp
* @date 2017年5月26日 下午8:45:38 
* @version V1.0   
*/
package com.zjdiepu.www.biz.zpp;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.type.CreditPeopleType;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.util.ZhppDateUtil;
import com.zjdiepu.www.dao.base.DpBaseDealerInfoMapper;
import com.zjdiepu.www.dao.dh.DhRemindLoanMapper;
import com.zjdiepu.www.dao.dh.FkInsureListMapper;
import com.zjdiepu.www.dao.dz.DzLendingMapper;
import com.zjdiepu.www.dao.dz.DzLoanExitMapper;
import com.zjdiepu.www.dao.dz.DzMortgageMapper;
import com.zjdiepu.www.dao.fk.FkAuditListMapper;
import com.zjdiepu.www.dao.other.OtherBusiSalersChangeMapper;
import com.zjdiepu.www.dao.system.BaseBusiUnitMapper;
import com.zjdiepu.www.dao.system.BaseSalersmanMapper;
import com.zjdiepu.www.dao.yw.YwBusinessBuyerMapper;
import com.zjdiepu.www.dao.yw.YwBusinessMapper;
import com.zjdiepu.www.dao.zpp.DaiZhongYwDao;
import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.dao.zx.ZxQueryCreditApplyMapper;
import com.zjdiepu.www.ibiz.base.ISerialNumberService;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.zpp.DaiZhongYwService;
import com.zjdiepu.www.model.base.dto.DpBaseDealerInfo;
import com.zjdiepu.www.model.dh.dto.DhRemindLoan;
import com.zjdiepu.www.model.dz.dto.DzLending;
import com.zjdiepu.www.model.dz.dto.DzLoanExit;
import com.zjdiepu.www.model.dz.dto.DzMortgage;
import com.zjdiepu.www.model.other.dto.OtherBusiSalersChange;
import com.zjdiepu.www.model.system.dto.BaseBusiUnit;
import com.zjdiepu.www.model.system.dto.BaseSalersman;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.yw.dto.YwBusinessBuyer;
import com.zjdiepu.www.model.zpp.dzyw.vo.BusinessSaveFkAuditListVo;
import com.zjdiepu.www.model.zpp.dzyw.vo.BusinessVo;
import com.zjdiepu.www.model.zpp.dzyw.vo.FkAuditListVo;
import com.zjdiepu.www.model.zpp.pub.ext.ParamsExt;
import com.zjdiepu.www.model.zpp.pub.ext.UpdateYwExt;
import com.zjdiepu.www.model.zpp.pub.vo.ParamsVo;

/**      
 * 项目名称：diepu-parent-biz   
 * 类名称：DaiZhongYwServiceImpl   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月26日 下午8:45:38   
 * 修改人：zhangpp
 * 修改时间：2017年5月26日 下午8:45:38   
 * 修改备注：   
 * @version V1.0     
 */
@Service
public class DaiZhongYwServiceImpl implements DaiZhongYwService
{

	@Autowired
	private DaiZhongYwDao daiZhongYwDao;
	
	@Autowired
	private ICachedDictionaryService iCachedDictionaryService; 
	
	@Autowired
	private ISerialNumberService ISerialNumberService;
	
	@Autowired
	private FkInsureListMapper fkInsureListMapper;
	
	@Autowired
	private DzLendingMapper dzLendingMapper;
	
	@Autowired
	private YwBusinessMapper ywBusinessMapper;
	
	@Autowired
	private DzLoanExitMapper dzLoanExitMapper;
	
	@Autowired
	private DzMortgageMapper dzMortgageMapper;
	
	@Autowired
	private DhRemindLoanMapper dhRemindLoanMapper;
	
	@Autowired
	private DpBaseDealerInfoMapper dpBaseDealerInfoMapper;
	
	@Autowired
	private BaseSalersmanMapper baseSalersmanMapper;
	
	@Autowired
	private FkAuditListMapper fkAuditListMapper;
	
	@Autowired
	private ZxQueryCreditApplyMapper zxQueryCreditApplyMapper;
	
	@Autowired
	private OtherBusiSalersChangeMapper otherBusiSalersChangeMapper;
	
	@Autowired
	private BaseBusiUnitMapper baseBusiUnitMapper;
	
	@Autowired
	private PublicDao publicDao;
	
	@Autowired
	private YwBusinessBuyerMapper ywBusinessBuyerMapper;
	
	/* 
	* @author zhangpp
	* <p>Title: getBusinessVoList</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#getBusinessVoList(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt) 
	* @version V1.0
	*/
	@Override
	public List<BusinessVo> getBusinessVoList(ParamsExt paramsExt) {
		
		return daiZhongYwDao.getBusinessVoList(paramsExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: countByExtBusinessVoList</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#countByExtBusinessVoList(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt) 
	* @version V1.0
	*/
	@Override
	public int countByExtBusinessVoList(ParamsExt paramsExt) {
		
		return daiZhongYwDao.countByExtBusinessVoList(paramsExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: getYwBusinessSaveFkAuditList</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#getYwBusinessSaveFkAuditList(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt) 
	* @version V1.0
	*/
	@Override
	public FkAuditListVo getYwBusinessSaveFkAuditList(ParamsExt paramsExt) {
		
		
		//条件   业务信息表的主键
		String whereSql = " and t.id = '"+paramsExt.getBusiId()+"' ";
		paramsExt.setWhereSql(whereSql);
		
		//查询要插入的数据
		BusinessSaveFkAuditListVo businessSaveFkAuditListVo = daiZhongYwDao.getYwBusinessSaveFkAuditList(paramsExt);
		
		if(null == businessSaveFkAuditListVo || ("").equals(businessSaveFkAuditListVo))
		{
			return null;
		}
		
		businessSaveFkAuditListVo.setChannelTypeName(iCachedDictionaryService.getName(businessSaveFkAuditListVo.getChannelType(), DataDicType.CHANNEL_TYPE));
		businessSaveFkAuditListVo.setChannelStatusName(iCachedDictionaryService.getName(businessSaveFkAuditListVo.getChannelStatus(), DataDicType.CHANNEL_STATUS));
		
		//当前的时间
		Date time = ZhppDateUtil.strToTimestamp(ZhppDateUtil.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss");
		//当前的时间
		
		//生成业务的编号信息
		//Integer queryCreditApplyCode = ISerialNumberService.createSerialNumber(CodeType.CREDIT_APPLY,null, false);
		//生成业务的编号信息
				
		//加入模型队列
		FkAuditListVo ywFkAuditListVo = new FkAuditListVo();
		ywFkAuditListVo.setBusi_id(paramsExt.getBusiId());
		ywFkAuditListVo.setBusi_confirm_time(time);
		ywFkAuditListVo.setLoan_amount(businessSaveFkAuditListVo.getRealLoanAmount());
		ywFkAuditListVo.setChannel_status(businessSaveFkAuditListVo.getChannelStatus());
		ywFkAuditListVo.setChannel_status_name(businessSaveFkAuditListVo.getChannelStatusName());
		ywFkAuditListVo.setChannel_type(businessSaveFkAuditListVo.getChannelType());
		ywFkAuditListVo.setChannel_type_name(businessSaveFkAuditListVo.getChannelTypeName());
		ywFkAuditListVo.setDealer(businessSaveFkAuditListVo.getDealerName());
		ywFkAuditListVo.setDepartment_name(businessSaveFkAuditListVo.getOrgName());
		ywFkAuditListVo.setCus_name(businessSaveFkAuditListVo.getCustomerName());
		ywFkAuditListVo.setCus_idno(businessSaveFkAuditListVo.getCustomerNo());
		ywFkAuditListVo.setBankname(businessSaveFkAuditListVo.getBankLoan());
		ywFkAuditListVo.setSalersman_name(businessSaveFkAuditListVo.getSalersmanName());
		ywFkAuditListVo.setOperate_status(0);
		ywFkAuditListVo.setAccept_date(time);
		ywFkAuditListVo.setAssigning_task_type(0);
		ywFkAuditListVo.setStatus_list(1);
		ywFkAuditListVo.setDealerLevel(businessSaveFkAuditListVo.getDealerLevel());
		ywFkAuditListVo.setCustomer_id(businessSaveFkAuditListVo.getCustomerId());
		return ywFkAuditListVo;
	}

	/* 
	* @author zhangpp
	* <p>Title: bankDaiKuanDataOp</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#bankDaiKuanDataOp(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	/*  
	*  @author  zhangpp
	*  <p>Title:  bankDaiKuanDataOp</p>  
	*  <p>Description:  </p>  
	*  @param paramsExt
	*  @param currentUser  
	*  @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#bankDaiKuanDataOp(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt, com.zjdiepu.www.base.core.AbstractSysUser)  
	*  @version  V1.0
	*/
	@Override
	@SuppressWarnings("deprecation")
	public void diepuBankDaiKuanDataOp(ParamsExt paramsExt,AbstractSysUser currentUser) 
	{
		
		
		if(null == currentUser || ("").equals(currentUser))
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		
		String userId = currentUser.getId();
		String modifierName = currentUser.getName();
		
		
		//添加  dz_lending  表数据
		DzLending dzLending = new DzLending();
		dzLending.setTimeLending(paramsExt.getTime_lending());
		dzLending.initInsertData(currentUser.getId(), currentUser.getName());
		dzLending.setBusiId(paramsExt.getBusiId());
//		dzLending.setCusId(currentUser.getId()); //2017-12-16 当前用户ID不能存入客户ID
		dzLending.setCusId(paramsExt.getCustomerId());
		dzLending.setAmountLending(paramsExt.getAmount_lending());
		dzLending.setFeeService(paramsExt.getFeeService());
		dzLending.setAmountLoaning(paramsExt.getAmountLoaning());
		dzLendingMapper.insert(dzLending);
		
		//必须参数对象
		if(null == paramsExt || ("").equals(paramsExt))
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		//业务新表的主键
		String busiId = paramsExt.getBusiId();
		if(null == busiId || ("").equals(busiId))
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		//查询业务信息表数据
		YwBusiness yw = ywBusinessMapper.selectByPrimaryKey(busiId);
		if(null == yw || ("").equals(yw))
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		}
		
		//现在执行修改为银行已放款
		//以前是 如果原业务状态为“车辆已抵押”，将业务状态更改为“还款中”，否则将 业务状态更改为“银行已放款”   现在 直接修改为  “银行已放款”
		//表dh_放款还款提醒已经调整，删除了一些字段
		int busiStatus = 500;
		
		//修改业务表数据 
		YwBusiness ywBusiness = new YwBusiness();
		ywBusiness.setId(paramsExt.getBusiId());
		ywBusiness.setBusiStatus(busiStatus);
		ywBusiness.setTimeLending(dzLending.getTimeLending());
		ywBusiness.initUpdateData(userId, modifierName);
		int updateCount = ywBusinessMapper.updateByPrimaryKeySelective(ywBusiness);
		if(updateCount == 0)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
		} 
		else if(updateCount > 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
		}
		
		//当前的时间
		//Date time = ZhppDateUtil.strToTimestamp(ZhppDateUtil.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss");
		
		//查询模型数据
		FkAuditListVo auditList = getYwBusinessSaveFkAuditList(paramsExt);
		
		if(null != auditList && !("").equals(auditList))
		{
			//插入还款提醒表
			DhRemindLoan dhRemindLoan = new DhRemindLoan();
			dhRemindLoan.initInsertData(userId, modifierName);
			dhRemindLoan.setBusiId(busiId);
			dhRemindLoan.setCusId(auditList.getCustomer_id());
			//dhRemindLoan.setTimeLending(time);
			dhRemindLoan.setTimeLending(paramsExt.getTime_lending());
			dhRemindLoan.setCusName(auditList.getCus_name());
			dhRemindLoan.setCusIdno(auditList.getCus_idno());
			dhRemindLoan.setLoanAmount(auditList.getLoan_amount());
			dhRemindLoan.setChannelTypeName(auditList.getChannel_type_name());
			
			//增加手机号码，从购车人信息表中获取  modified by zzj  ---start
			YwBusinessBuyer ywBusinessBuyer=new YwBusinessBuyer();
			ywBusinessBuyer.setCarManType(CreditPeopleType.ZHU_JIE_REN.getCode());
			ywBusinessBuyer.setDpStatus(DpStatus.NORMAL.getCode());
			ywBusinessBuyer.setBusiId(busiId);
			ywBusinessBuyer=ywBusinessBuyerMapper.selectRefined(ywBusinessBuyer);
			if(ywBusinessBuyer!=null){
				dhRemindLoan.setTel1(ywBusinessBuyer.getTel1());
			}
			//-----------------------end
			//查询经销商
			dhRemindLoan.setDealer(auditList.getDealer());
			dhRemindLoan.setDealerLevel(iCachedDictionaryService.getName(auditList.getDealerLevel(), DataDicType.DEALER_LEVEL));
			dhRemindLoan.setDepartmentName(auditList.getDepartment_name());
			dhRemindLoan.setSalersmanName(auditList.getSalersman_name());
			dhRemindLoan.setBankname(iCachedDictionaryService.getName(auditList.getBankname(), DataDicType.LOAN_BANK));
			int insertCount = dhRemindLoanMapper.insert(dhRemindLoan);
			if(insertCount < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"insert DhRemindLoan fail");
			}
		}
	}

	/* 
	* @author zhangpp
	* <p>Title: gettimeArrive</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#gettimeArrive(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt) 
	* @version V1.0
	*/
	@Override
	public ParamsVo gettimeArrive(ParamsExt paramsExt) {
		
		return daiZhongYwDao.gettimeArrive(paramsExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: daiZhongYwTuiDaiBiao</p> 
	* <p>Description: </p> 
	* @param dzLoanExit
	* @param ywBusiness
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#daiZhongYwTuiDaiBiao(com.zjdiepu.www.model.dz.dto.DzLoanExit, com.zjdiepu.www.model.yw.dto.YwBusiness, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void diepuDaiZhongYwTuiDaiBiao(DzLoanExit dzLoanExit,YwBusiness ywBusiness, AbstractSysUser currentUser) 
	{
		
		
		String userId = currentUser.getId();
		String creatorName = currentUser.getName();
		
		dzLoanExit.initInsertData(userId, creatorName);
		int saveCount = dzLoanExitMapper.insert(dzLoanExit);
		if(saveCount == 0)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		} 
		else if(saveCount > 1)
		{
			throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
		}
		
		//修改业务信息表状态 9810
		ywBusiness.initUpdateData(userId, creatorName);
		int updateCount = ywBusinessMapper.updateByPrimaryKeySelective(ywBusiness);
		if(updateCount == 0)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		} 
		else if(updateCount > 1)
		{
			throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
		}
		
		//业务信息编号
		String busiId = ywBusiness.getId();

		//查询待审批列表是否有数据
		String sqlXmls = "select t.id from fk_audit_list t where t.busi_id = '"+busiId+"' and t.status_list = 1 and t.dp_status = 1";
		List<Map<String, String>> list = publicDao.queryWhereSql(sqlXmls);
		if(null == list || 0 == list.size())
		{
			return;
		}
		
		//退贷之后把所有待审批的列表都清空掉
		sqlXmls = "update fk_audit_list t set t.dp_status = 3 where t.busi_id = '"+busiId+"' and t.status_list = 1 and t.dp_status = 1";
		updateCount = publicDao.updateWhereSqlXmls(sqlXmls);
		if(updateCount < 1)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"delete fk_audit_list fail ");
		} 
		
	}

	/* 
	* @author zhangpp
	* <p>Title: daiZhongYwDiYaQueRrnSave</p> 
	* <p>Description: </p> 
	* @param dzMortgage
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#daiZhongYwDiYaQueRrnSave(com.zjdiepu.www.model.dz.dto.DzMortgage, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void diepuDaiZhongYwDiYaQueRrnSave(DzMortgage dzMortgage,AbstractSysUser currentUser) 
	{
		
		String userId = currentUser.getId();
		String creatorName = currentUser.getName();
		
		String busiId = dzMortgage.getBusiId();
		
		//查询当前的记录值
		DzMortgage mortgage = new DzMortgage();
		mortgage.setBusiId(busiId);
		mortgage.setDpStatus(1);
		mortgage = dzMortgageMapper.selectRefined(mortgage);
		
		if(null != mortgage)
		{
			if(null != mortgage.getStatusMortgageInfo() && mortgage.getStatusMortgageInfo() == 20)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"该数据已经提交抵押");
			}
		}
		
		//查询业务数据
		YwBusiness business = ywBusinessMapper.selectByPrimaryKey(busiId);
		if(null == business)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"ywBusinessMapper is null");
		}
		
		//插入
		if(null == mortgage)
		{
			dzMortgage.initInsertData(userId, creatorName);
			dzMortgage.setCusId(business.getCustomerId());
			if(null != dzMortgage.getStatusMortgage() && dzMortgage.getStatusMortgage() == 3)
			{
				dzMortgage.setStatusMortgage(null);
			}
			int inserCount = dzMortgageMapper.insert(dzMortgage);
			if(inserCount < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"dzMortgageMapper insert error");
			}
			
			if(null != dzMortgage.getStatusMortgage())
			{
				if(dzMortgage.getStatusMortgage() == 1)
			    {
			    	business.setPledgeTime(dzMortgage.getDateMortgage());
			    	int count = ywBusinessMapper.updateByPrimaryKeySelective(business);
			    	if(count < 1)
			    	{
			    		throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessMapper updateByPrimaryKeySelective error");
			    	}
			    }
			}
			return;
		}
		
		//修改业抵押确认数据
		dzMortgage.setId(mortgage.getId());
		if(null != dzMortgage.getStatusMortgage() && dzMortgage.getStatusMortgage() == 3)
		{
			dzMortgage.setStatusMortgage(null);
		}
		int count = dzMortgageMapper.updateByPrimaryKeySelective(dzMortgage);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"dzMortgageMapper update error");
		}
		
		if(null != dzMortgage.getStatusMortgage())
		{
			if(dzMortgage.getStatusMortgage() == 1)
		    {
		    	business.setPledgeTime(dzMortgage.getDateMortgage());
		    	count = ywBusinessMapper.updateByPrimaryKeySelective(business);
		    	if(count < 1)
		    	{
		    		throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessMapper updateByPrimaryKeySelective error");
		    	}
		    }
		}
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  getYwYuanList</p>  
	*  <p>Description:  </p>  
	*  @param paramsExt
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#getYwYuanList(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt)  
	*  @version  V1.0
	*/
	@Override
	public List<BusinessVo> getYwYuanList(ParamsExt paramsExt) {
		
		return daiZhongYwDao.getYwYuanList(paramsExt);
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  countYwYuanList</p>  
	*  <p>Description:  </p>  
	*  @param paramsExt
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#countYwYuanList(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt)  
	*  @version  V1.0
	*/
	@Override
	public int countYwYuanList(ParamsExt paramsExt) {
		
		return daiZhongYwDao.countYwYuanList(paramsExt);
	}

	

	/*  
	*  @author  zhangpp
	*  <p>Title:  updateYw</p>  
	*  <p>Description:  </p>  
	*  @param currentUser
	*  @param updateYwExt  
	*  @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#updateYw(com.zjdiepu.www.base.core.AbstractSysUser, com.zjdiepu.www.model.zpp.pub.ext.UpdateYwExt)  
	*  @version  V1.0
	*/
	@Override
	public void updateYw(AbstractSysUser currentUser, UpdateYwExt updateYwExt) {
		
		String userId = currentUser.getId();
		String name = currentUser.getName();
		
		String busiId = updateYwExt.getBusiId();
		String salesmanIdOld = updateYwExt.getSalesmanIdOld();
		String salesmanIdNow = updateYwExt.getSalesmanIdNow();
		
		
		//查询原来的业务员表
		BaseSalersman salesmanOld = baseSalersmanMapper.selectByPrimaryKey(salesmanIdOld);
		if(null == salesmanOld || ("").equals(salesmanOld))
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"salesmanOld is null");
		}
		
		//查询当前的业务员
		BaseSalersman salesmanNow = baseSalersmanMapper.selectByPrimaryKey(salesmanIdNow);
		if(null == salesmanNow || ("").equals(salesmanNow))
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"salesmanNow is null");
		}
		
		//查询业务表数据
		YwBusiness ywBusiness = ywBusinessMapper.selectByPrimaryKey(busiId);
		if(null == ywBusiness || ("").equals(ywBusiness))
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"ywBusiness is null");
		}
		
		//查询经销商表
		DpBaseDealerInfo dpBaseDealerInfo = dpBaseDealerInfoMapper.selectByPrimaryKey(ywBusiness.getDealerId());
		if(null == dpBaseDealerInfo || ("").equals(dpBaseDealerInfo))
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"dpBaseDealerInfo is null");
		}
		
		//原有的业务单位
		BaseBusiUnit baseBusiUnitOLd = baseBusiUnitMapper.selectByPrimaryKey(salesmanOld.getUnitId());
		if(null == baseBusiUnitOLd || ("").equals(baseBusiUnitOLd))
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"baseBusiUnitOLd is null");
		}
		
		//现在的业务单位
		BaseBusiUnit baseBusiUnitNow = baseBusiUnitMapper.selectByPrimaryKey(salesmanNow.getUnitId());
		if(null == baseBusiUnitNow || ("").equals(baseBusiUnitNow))
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"baseBusiUnitNow is null");
		}
		
		OtherBusiSalersChange otherBusiSalersChange = new OtherBusiSalersChange();
		otherBusiSalersChange.initInsertData(userId, name);
		otherBusiSalersChange.setBusiId(ywBusiness.getId());
		otherBusiSalersChange.setBusiCode(ywBusiness.getBusiCode());
		
		otherBusiSalersChange.setSalesmanIdOld(salesmanOld.getId());
		otherBusiSalersChange.setSalesmanCodeOld(salesmanOld.getSalersmanCode());
		otherBusiSalersChange.setSalesmanNameOld(salesmanOld.getName());
		otherBusiSalersChange.setBusiUnitNameOld(baseBusiUnitOLd.getOrgName());
		
		otherBusiSalersChange.setSalesmanIdNow(salesmanNow.getId());
		otherBusiSalersChange.setSalesmanCodeNow(salesmanNow.getSalersmanCode());
		otherBusiSalersChange.setSalesmanNameNow(salesmanNow.getName());
		otherBusiSalersChange.setBusiUnitNameNow(baseBusiUnitNow.getOrgName());
		
		otherBusiSalersChange.setCustomerId(ywBusiness.getCustomerId());
		otherBusiSalersChange.setCustomerName(ywBusiness.getCustomerName());
		otherBusiSalersChange.setCustomerNo(ywBusiness.getCustomerNo());
		otherBusiSalersChange.setBankname(iCachedDictionaryService.getName(ywBusiness.getBankLoan(), DataDicType.LOAN_BANK));
		otherBusiSalersChange.setLoanAmount(ywBusiness.getRealLoanAmount());
		otherBusiSalersChange.setChannelTypeName(iCachedDictionaryService.getName(ywBusiness.getChannelType(), DataDicType.CHANNEL_TYPE));
		otherBusiSalersChange.setDealerLevel(iCachedDictionaryService.getName(dpBaseDealerInfo.getDealerLevel(), DataDicType.DEALER_LEVEL));
		otherBusiSalersChange.setDealerName(dpBaseDealerInfo.getDealerName());
		otherBusiSalersChange.setStatusBusiSalersChange(0);
		otherBusiSalersChange.setRemarks(updateYwExt.getRemarks());
		int count = otherBusiSalersChangeMapper.insert(otherBusiSalersChange);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
		}
		
		//业务员数据表
		YwBusiness business = new YwBusiness();
		business.setId(ywBusiness.getId());
		business.setSalesmanId(salesmanNow.getId());
		business.setSalesmanCode(salesmanNow.getSalersmanCode());
		count = ywBusinessMapper.updateByPrimaryKeySelective(business);
		if(count < 1)
		{
			//throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"YwBusiness error");
		}
		
		//审批列表
		String sqlXmls = "update fk_audit_list t set t.salersman_name = '"+salesmanNow.getName()+"' where t.busi_id = '"+ywBusiness.getId()+"' and t.dp_status = 1 and t.status_list = 1";
		count = publicDao.updateWhereSqlXmls(sqlXmls);
		if(count < 1)
		{
			//throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"fk_audit_list error");
		}
		
		//征信主表
		sqlXmls = "update zx_query_credit_apply t set t.salersman_id_then = '"+salesmanNow.getId()+"' where t.busi_id = '"+ywBusiness.getId()+"' and t.dp_status = 1";
		count = publicDao.updateWhereSqlXmls(sqlXmls);
		if(count < 1)
		{
			//throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zx_query_credit_apply error");
		}
		
		//征信查询表
		sqlXmls = "update zx_credit_query t set t.salersman_id_then = '"+salesmanNow.getId()+"' where t.busi_id = '"+ywBusiness.getId()+"' and t.dp_status = 1";
		count = publicDao.updateWhereSqlXmls(sqlXmls);
		if(count < 1)
		{
			//throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zx_credit_query error");
		}
		
//		String sqlXmls = "select bus.id,saler.id salerId,saler.salersman_code from yw_business bus left join base_customer cus on bus.customer_id = cus.id left join base_salersman saler on saler.id = cus.salesman_id where bus.dp_status = 1 and saler.dp_status = 1 and cus.dp_status = 1";
//		List<Map<String, String>> list = publicDao.queryWhereSql(sqlXmls);
//		for(int i=0;i<list.size();i++)
//		{
//			Map<String, String> maps = list.get(i);
//			
//			sqlXmls = "update yw_business t set t.salesman_id = '"+maps.get("salerId")+"' ,t.salesman_code = '"+maps.get("salersman_code")+"' where t.id = '"+maps.get("id")+"' and t.dp_status = 1";
//			int count = publicDao.updateWhereSqlXmls(sqlXmls);
//			if(count < 1)
//			{
//				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
//			}
//		}
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  diepuDiYaQueRen</p>  
	*  <p>Description:  </p>  
	*  @param currentUser
	*  @param dzMortgage  
	*  @see com.zjdiepu.www.ibiz.zpp.DaiZhongYwService#diepuDiYaQueRen(com.zjdiepu.www.base.core.AbstractSysUser, com.zjdiepu.www.model.dz.dto.DzMortgage)  
	*  @version  V1.0
	*/
	@Override
	public void diepuDiYaQueRen(AbstractSysUser currentUser,DzMortgage dzMortgage) 
	{
		
		
		dzMortgage.setStatusMortgageInfo(20);
		int count = dzMortgageMapper.updateByPrimaryKeySelective(dzMortgage);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"dzMortgageMapper error");
		}
		
		//查询抵押确认信息
		dzMortgage = dzMortgageMapper.selectByPrimaryKey(dzMortgage.getId());
		if(null == dzMortgage)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"dzMortgage is null");
		}
		
		YwBusiness ywBusiness = new YwBusiness();
		ywBusiness.setId(dzMortgage.getBusiId());
		ywBusiness.setPledgeTime(dzMortgage.getDateMortgage());
		count = ywBusinessMapper.updateByPrimaryKeySelective(ywBusiness);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessMapper error");
		}
	}
}
	